/*
 * Template used by clientMod.js to implement require in the client
 */
if (!window.require) {
	window.require = function (id) {
		
		if ("/" != id[0]) {
			id = "/" + id
		}
		
		try {
			if (!require.modules[id]) {
	
				var modCode = require.modCode[id]
				var exports = {
					dependencies:[]
				}
				require.modules[id] = exports
				var module = {
					id : id
				}
				
				var abs_id = function( other_id ) {
					other_id = "" + other_id
					
					if ("./" == other_id.substring(0,2)) {
						return id.substring(0, id.lastIndexOf("/")) + other_id.substring(1)
					}
					
					if ("/" != other_id[0]) {
						return "/" + other_id
					}
					
					return other_id
				}
				
				var requireForModule = function(id) {
					id = abs_id(id)
					module.id = id
					var mod = require( id )
					var d = exports.dependencies
					
					if (d.indexOf(id) == -1) {
						d[d.length] = id
					}
					return mod
				}
				
				requireForModule.RequireError = require.RequireError
				requireForModule.env = require.env
				
				var context = {}
				
				if(!modCode) {
					throw new require.RequireError(id, "module not found")
				}
	
				modCode.call(context, requireForModule, exports, module) 
			}
	
			return require.modules[id]
		} catch (x) {
			if (x instanceof require.RequireError) {
				throw x
			} else {
				throw new require.RequireError(id, x)
			}
		} 
	}
	
	require.env = "browser"
	
	require.modCode = {}
	require.modules = {}
	
	require.RequireError = function(moduleId, cause) {
		this.moduleId = moduleId
		this.cause = cause
	}
	require.RequireError.prototype = {}
	require.RequireError.prototype.toString = function() {
		return "Error loading " + this.moduleId + ( this.cause ? ". Cause: " + this.cause : "" )
	}
	require.RequireError.prototype.name = "RequireError"
}

var newModCode = /*MOD_CODE*/
for (var n in newModCode) {
	require.modCode[n] = newModCode[n]
}
